package zj;

import java.util.ArrayList;
import java.util.List;

import zj.playCard.PlayerEntity;
import zj.playCard.PokerEntity;

public class PlayGames extends PokerEntity {

    static List<PlayerEntity> players = new ArrayList<PlayerEntity>();

    static int playerNum = 4;
    static int USER_HAVE_CARDS_NUM = 14;

    public static void initPokerGame() {
	char[] tempchars = INIT_RANDOM();
	int cardsSum = tempchars.length;
	// math.ceil() 向上取最大值
	USER_HAVE_CARDS_NUM = Math.round((long) Math.ceil((double) cardsSum / (double) playerNum));

	for (int i = 0; i < playerNum; i++) {
	    PlayerEntity pr = new PlayerEntity().setUserId(i + "").setUserName("player:" + i);
	    char[] initcards = new char[USER_HAVE_CARDS_NUM];
//	    for (int j = 0; j < 14; j++) {
//		if (i > 1 && j < 13)
//		    initcards[j] = tempchars[(j * playerNum) + i];
//		if (i < 2)
//		    initcards[j] = tempchars[(j * playerNum) + i];
//	    }

	    for (int j = 0; j < USER_HAVE_CARDS_NUM; j++)
		if ((j * playerNum) + i < cardsSum)
		    initcards[j] = tempchars[(j * playerNum) + i];

	    pr.setCards(initcards);
	    pr.cardsSerilizeabled();
	    players.add(pr);
	}
    }

    public static void main(String[] args) {
	initPokerGame();
	players.forEach(p -> System.out.println(p.getCardsName("")));
    }

}
